import { useIntersectionObserver } from '@vueuse/core'
export const lazyPlugin = {
    install(app) {
        //实现图片懒加载
        app.directive('img-lazy', {
            mounted(el, binding) {
                //console.log(el,binding.value)
                const { stop } = useIntersectionObserver(
                    el,
                    ([{ isIntersecting }]) => {
                        console.log(isIntersecting);
                        //true图片可以看到，false图片不可以看到
                        if (isIntersecting) {
                            el.src = binding.value;
                            stop();
                            //如果加载过一次，就不会加载第二次
                        }

                    },
                )
            }
        })
    }
}